
/**
 * 倒计时控件
 */
Component({
	/**
	 * 组件的属性列表
	 */
	options: {
	},
	properties: {
		color: String,
		fontsize: Number,
		max: Number,
		min: Number,
		score: Number,
		spacing: Number,
		wid: String
	},

	attached() {
		const _t = this;
		const score = Math.abs(~~Number(_t.data.score));
		_t.setData({
			max: _t.data.max,
			score
		});
	},

	methods: {
		get_score() {
			return this.data.score;
		},
		highlight(e: any) {
			const _t = this;
			const s = e.currentTarget.dataset.s;
			if (s === _t.data.score) {
				_t.render(s - 1);
			} else {
				_t.render(s);
			}
		},
		dark(e: any) {
			const _t = this;
			const s = e.currentTarget.dataset.s;
			if (s === _t.data.score) {
				_t.render(s + 1);
			} else {
				_t.render(s);
			}
		},
		render(s: number) {
			if (s < this.data.min) {
				this.triggerEvent('fdwe-choose', { max: this.data.max, min: this.data.min, score: this.data.min, wid: this.data.wid }, { bubbles: true });
				return;
			}
			this.setData({
				score: s
			});
			this.triggerEvent('fdwe-choose', { max: this.data.max, min: this.data.min, score: this.data.score, wid: this.data.wid }, { bubbles: true });
		}
	}
});
